﻿using System.Text;
using zTalk.Network;

namespace zTalk
{
    public interface IPacketHandler
    {
        void Handle(SocketBase client, Packet packet);
    }

    public class PacketHandlerBase
    {
        protected string[] getData(Packet packet)
        {
            string data = Encoding.UTF8.GetString(packet.Data);

            return Json.Decode<string[]>(data);
        }

        protected void sendData(SocketBase client, Opcodes opcode, string[] data)
        {
            Packet packet = Packet.Create(opcode, Json.Encode<string[]>(data));
            client.SendPacket(packet);
        }
    }

    public enum UserStatus
    {
        OFFLINE = 0,
        AFK = 1,
        ONLINE = 2,
    }

    public class UserProto
    {
        public string Username { get; set; }
        public UserStatus Status { get; set; }
        public string About { get; set; }
        public string Avatar { get; set; }
    }

    public class MessageProto
    {
        public string Source { get; set; }
        public string Destination { get; set; }
        public string Text { get; set; }
        public string Time { get; set; }
    }

    public class FileProto
    {
        public string Source { get; set; }
        public string Destination { get; set; }
        public string FileName { get; set; }
        public int Size { get; set; }
    }
}
